package com.zqxq.testsuit;

import java.io.IOException;

import org.testng.Assert;
import org.testng.annotations.Test;

import net.sf.json.JSONObject;

import com.google.gson.JsonObject;
import com.zqxq.api.*;
import com.zqxq.dataprovider.abnormalDataProvider;
import com.zqxq.dataprovider.normalDataProvider;

public class DistributionAPI {
	/**
	 * 正常登录。
	 *
	 */
	@Test	(dataProvider="NormalLogin",dataProviderClass=normalDataProvider.class)
	public static void Login(String url,String phone,String passwd) throws IOException {
		// TODO Auto-generated method stub
		JsonObject response = null;		
		String code;
		response = LoginAPI.Login(url,phone,passwd);
		System.out.println(response);
		//code = response.getString("code");
		code = response.get("code").getAsString();
		Assert.assertEquals(code, "1","登录成功");
	}
	
	/**
	 * 空密码登录。
	 *
	 */
	@Test   (dataProvider="nullPasswdLogin",dataProviderClass=abnormalDataProvider.class)
	public static void Login_misspwd(String url,String phone,String passwd) throws IOException {
		// TODO Auto-generated method stub
		JsonObject response = null;		
		String code;
		response = LoginAPI.Login(url,phone,passwd);		
		code = response.get("code").getAsString();
		//code = response.getString("code");		
		Assert.assertEquals(code, "2","空密码验证成功");
	}

	/**
	 * 错误密码登录。
	 *
	 */
	@Test   (dataProvider="errorPasswdLogin",dataProviderClass=abnormalDataProvider.class)
	public static void Login_errorpwd(String url,String phone,String passwd) throws IOException {
		// TODO Auto-generated method stub
		JsonObject response = null;		
		String code;
		response = LoginAPI.Login(url,phone,passwd);		
		code = response.get("code").getAsString();
		//code = response.getString("code");		
		Assert.assertEquals(code, "2","错误密码验证成功");
	}
	
	/**
	 * 首页banner_API。
	 *
	 */
	@Test
	public static void GetBanner() throws IOException {
		// TODO Auto-generated method stub
		String url="http://xjjq.newzqxq.com/api/index/banner/getbanner?app_key=FQJD";
		JsonObject response = null;		
		String code;
		response = BannerAPI.GetBanner(url);		
		code = response.get("code").getAsString();
		//code = response.getString("code");		
		Assert.assertEquals(code, "1","获取banner成功");
	}
	
	/**
	 * 产品列表API。
	 *
	 */
	@Test (dataProvider="findLoanProductList",dataProviderClass=normalDataProvider.class)
	public static void findLoanProductList(String url,String phone,String passwd) throws IOException {
		// TODO Auto-generated method stub
		
		JsonObject response = null;		
		String success;
		response = findLoanProductListAPI.findLoanProductListPost(url);		
		success = response.get("success").getAsString();
		//success = response.getString("success");
		//System.out.print(response);
		Assert.assertEquals(success, "true","获取个人数据成功");
	}
	
}
